package demo.dao.impl;

import demo.dao.UserMapper;
import demo.pojo.User;
import demo.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.awt.print.Book;
import java.util.ArrayList;
import java.util.List;

public class UserMapperImpl implements UserMapper{

    static List<User> list=new ArrayList<>();
    static {
        list.add(new User(6,"俄罗斯","ttk"));
        list.add(new User(7,"中国","nb"));
    }

    @Override
    public List<User> selectUser() {
        return list;
    }

    @Override
    public User selectUserById(int id) {
        for (User user:list){
            if(user.getId()==id){
                return user;
            }
        }
        return null;
    }

    @Override
    public int addUser(User user) {
        if(selectUserById(user.getId())==null){
            list.add(user);
            return 1;
        }
        return 0;
    }

    @Override
    public int updateUser(User user) {
        for(User user1:list){
            if(user1.getId()==user.getId()){
                user1.setName(user.getName());
                user1.setPassword(user.getPassword());
                return 1;
            }
        }

        return 0;
    }

    @Override
    public int deleteUser(int id) {
        for (User user:list){
            if(user.getId()==id){
                list.remove(user);
                return 1;
            }
        }
        return 0;
    }


}

